package com.ruoyi.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.project.domain.entity.ProjectGoods;
import com.ruoyi.project.domain.entity.ProjectStore;
import com.ruoyi.project.domain.query.ProjectStoreQuery;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface ProjectStoreMapper extends BaseMapper<ProjectStore> {
    @Delete("DELETE FROM project_store ")
    void deleteAll();

    @Delete("DELETE FROM project_store where datas = 'HC2024' ")
    void deleteAllHC2024();

    @Delete("DELETE FROM project_store where datas = 'HC2022' ")
    void deleteAllHC2022();

    @Delete("DELETE FROM project_store where datas = 'XXWL2018' ")
    void deleteAllXXWL2018();

    @Delete("DELETE FROM project_store where datas = 'XXWL' ")
    void deleteAllXXWL();


    List<ProjectStore> selectStorePage(ProjectStoreQuery query);


    @Select("SELECT * FROM project_store " +
            "WHERE goods_id = #{goodsId} " +
            "  AND storage_date BETWEEN #{startDate} AND #{endDate} " +
            "ORDER BY storage_date DESC")
    List<ProjectStore> selectStoreByGoodsId(
            @Param("goodsId") String goodsId,
            @Param("startDate") LocalDate startDate,
            @Param("endDate") LocalDate endDate);

    @Select("SELECT sum(amount) FROM project_store " +
            "WHERE goods_id = #{goodsId} ")
            Integer selectStoreCount(@Param("goodsId") String goodsId);

    @Select("SELECT sum(amount) FROM project_sale " +
            "WHERE goods_id = #{goodsId} ")
    Integer selectSaleCount(@Param("goodsId") String goodsId);


}
